package com.jianz.campus_markets.service.impl;

import com.baomidou.mybatisplus.core.injector.methods.DeleteById;
import com.baomidou.mybatisplus.core.injector.methods.SelectList;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jianz.campus_markets.domain.ResponseResult;
import com.jianz.campus_markets.domain.entity.Product;
import com.jianz.campus_markets.mapper.ProductMapper;
import com.jianz.campus_markets.service.AdminService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Jianz
 * @version 1.0
 * @Description
 * @Email jianz8153.gmail.com
 * @Date 2023/11/27 2:03
 */

@Service
public class AdminServiceImpl extends ServiceImpl<ProductMapper, Product> implements AdminService {
    @Override
    public ResponseResult getAllProducts() {
        List<Product> products = getBaseMapper().selectList(null);
        return ResponseResult.okResult(products);
    }

    @Override
    public ResponseResult passProduct(int productId) {
        Product product = getById(productId);
        product.setStatus(1);
        updateById(product);
        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult failProduct(int productId) {
        Product product = getById(productId);
        product.setStatus(2);
        updateById(product);
        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult offProduct(int productId) {

        getBaseMapper().deleteById(productId);

        return ResponseResult.okResult();
    }
}
